﻿Public Class fTiposDocumentos
    Dim daBodega As lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
    Dim daCCosto As lbGlobalcom.dsContabilidadTableAdapters.CON_CCOSTOTableAdapter
    Dim daSedes As lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
    Dim daConsec As lbGlobalcom.dsGlobalTableAdapters.GLO_CONSECUTIVOTableAdapter
    Dim daListaPre As lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
    Dim daTipoDoc As lbGlobalcom.dsGlobalTableAdapters.GLO_TIPODOCUMENTOTableAdapter
    Dim daListaTablas As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
    Private Sub LLenaFiltroTipo()
        Dim dt As New lbGlobalcom.dsGlobal.GLO_DATOSTABLASDataTable
        Try
            daListaTablas.FillByIdGrupo(dt, "td")
            Dim dr As lbGlobalcom.dsGlobal.GLO_DATOSTABLASRow = dt.NewGLO_DATOSTABLASRow
            dr.ID = -1
            dr.IDGRUPO = "td"
            dr.DESCRIPCION = "Sin Filtrar"
            dt.Rows.Add(dr)
            dr = Nothing
            Me.cbFiltroTipo.ComboBox.DataSource = dt
            Me.cbFiltroTipo.ComboBox.DisplayMember = "DESCRIPCION"
            Me.cbFiltroTipo.ComboBox.ValueMember = "ID"
            Me.cbFiltroTipo.ComboBox.SelectedValue = -1
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    Private Sub LlenaFiltroDocumento()
        Try
            DsGlo_TipoDoc.GLO_TIPODOCUMENTO.Rows.Clear()
            If TypeOf Me.cbFiltroTipo.ComboBox.SelectedValue Is Decimal AndAlso Me.cbFiltroTipo.ComboBox.SelectedValue <> -1 Then
                daTipoDoc.FillByDocEs(DsGlo_TipoDoc.GLO_TIPODOCUMENTO, Me.cbFiltroTipo.ComboBox.SelectedValue)
                'Dim dr As lbGlobalcom.dsGlobal.GLO_TIPODOCUMENTORow = dt.NewGLO_TIPODOCUMENTORow
                'dr.TIPODOC = -1
                'dr.DESCRIPCION = "Sin Filtrar"
                'dt.Rows.Add(dr)
                'dr = Nothing
                Me.cbFiltroDocumento.ComboBox.DataSource = DsGlo_TipoDoc.GLO_TIPODOCUMENTO
                Me.cbFiltroDocumento.ComboBox.DisplayMember = "DESCRIPCION"
                Me.cbFiltroDocumento.ComboBox.ValueMember = "TIPODOC"
                Me.cbFiltroDocumento.ComboBox.SelectedValue = "-1"
                gvDocumentos.DataSource = DsGlo_TipoDoc.GLO_TIPODOCUMENTO
            ElseIf TypeOf Me.cbFiltroTipo.ComboBox.SelectedValue Is Decimal AndAlso Me.cbFiltroTipo.ComboBox.SelectedValue = -1 Then
                Me.cbFiltroDocumento.ComboBox.DataSource = Nothing
                Me.cbFiltroDocumento.ComboBox.DisplayMember = "DESCRIPCION"
                Me.cbFiltroDocumento.ComboBox.ValueMember = "TIPODOC"
                Me.cbFiltroDocumento.ComboBox.SelectedValue = -1
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub APLICAIVAListBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles APLICAIVAListBox.GotFocus
        Me.tsEstadoInfo.Text = "S->Si o N->No"
    End Sub

    Private Sub APLICAIVAListBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles APLICAIVAListBox.LostFocus
        Me.tsEstadoInfo.Text = ""
    End Sub

    Private Sub btnBuscaBodOri_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaBodOri.Click
        Dim fListBod As New fListaBodegas
        If fListBod.ShowDialog = Windows.Forms.DialogResult.OK Then
            BODEGADETextBox.Text = fListBod.Bodega
        End If
    End Sub

    Private Sub btnBuscaBodDes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBodDes.Click
        Dim fListBod As New fListaBodegas
        If fListBod.ShowDialog = Windows.Forms.DialogResult.OK Then
            BODEGAPARATextBox.Text = fListBod.Bodega
        End If
    End Sub

    Private Sub BODEGADETextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BODEGADETextBox.TextChanged
        If BODEGADETextBox.Text.Trim.Length > 0 Then
            Me.lbBodegaOri.Text = daBodega.GetNombreBodega(BODEGADETextBox.Text)
        Else
            Me.lbBodegaOri.Text = ""
        End If
    End Sub

    Private Sub fTiposDocumentos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daBodega = New lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
        daCCosto = New lbGlobalcom.dsContabilidadTableAdapters.CON_CCOSTOTableAdapter
        daSedes = New lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
        daConsec = New lbGlobalcom.dsGlobalTableAdapters.GLO_CONSECUTIVOTableAdapter
        daListaPre = New lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
        daTipoDoc = New lbGlobalcom.dsGlobalTableAdapters.GLO_TIPODOCUMENTOTableAdapter
        daListaTablas = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
        Try
            lbGlobalcom.cGeneral.ActivaControles(Me.Controls, False)
            LLenaFiltroTipo()
            LlenaFiltroDocumento()
            daListaTablas.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "td")
            daListaTablas.FillByIdGrupo(DsValorApl.GLO_DATOSTABLAS, "vd")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BODEGAPARATextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BODEGAPARATextBox.TextChanged
        If BODEGAPARATextBox.Text.Trim.Length > 0 Then
            Me.lbBodegaDes.Text = daBodega.GetNombreBodega(BODEGAPARATextBox.Text)
        Else
            Me.lbBodegaDes.Text = ""
        End If
    End Sub

    Private Sub btnBuscaCCosto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaCCosto.Click
        Dim fLisCC As New fListaCCostos
        If fLisCC.ShowDialog = Windows.Forms.DialogResult.OK Then
            IDCCOSTOTextBox.Text = fLisCC.CCosto
        End If
    End Sub

    Private Sub IDCCOSTOTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDCCOSTOTextBox.TextChanged
        If IDCCOSTOTextBox.Text.Trim.Length > 0 Then
            Me.lbCCosto.Text = daCCosto.GetNombreCCosto(IDCCOSTOTextBox.Text)
        Else
            Me.lbCCosto.Text = ""
        End If
    End Sub

    Private Sub btnBuscaSedes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaSedes.Click
        Dim fLisSedes As New fListaSedes
        If fLisSedes.ShowDialog = Windows.Forms.DialogResult.OK Then
            IDSEDETextBox.Text = fLisSedes.Sede
        End If
    End Sub

    Private Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.KeyChar = e.KeyChar.ToString.ToUpper
    End Sub

    Private Sub IDSEDETextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDSEDETextBox.TextChanged
        If IDSEDETextBox.Text.Trim.Length > 0 Then
            Me.lbSedes.Text = daSedes.GetNombreSede(IDSEDETextBox.Text)
        Else
            Me.lbSedes.Text = ""
        End If
    End Sub

    Private Sub btnBuscaConsec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaConsec.Click
        Dim fLisCons As New fListaConsec
        If fLisCons.ShowDialog = Windows.Forms.DialogResult.OK Then
            IDCONSECUTIVOTextBox.Text = fLisCons.Consec
        End If
    End Sub

    Private Sub IDCONSECUTIVOTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDCONSECUTIVOTextBox.TextChanged
        If IDCONSECUTIVOTextBox.Text.Trim.Length > 0 Then
            Me.lbConsec.Text = daConsec.GetNombreConsecutivo(IDCONSECUTIVOTextBox.Text)
        Else
            Me.lbConsec.Text = ""
        End If
    End Sub

   
    Private Sub btnBuscaListaPrecios_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaListaPrecios.Click
        Dim fLisPre As New fListaPrecios
        If fLisPre.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.IDLISTATextBox.Text = fLisPre.Lista
        End If
    End Sub

    Private Sub IDLISTATextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDLISTATextBox.TextChanged
        If IDLISTATextBox.Text.Trim.Length > 0 Then
            Me.lbListaPrecios.Text = daListaPre.GetNombreLista(IDLISTATextBox.Text)
        Else
            Me.lbListaPrecios.Text = ""
        End If
    End Sub

    Private Sub btnBuscaDocConv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaDocConv.Click
        Dim fLDoc As New fListaTipoDocs
        If fLDoc.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.TIPODOCCONVIERTETextBox.Text = fLDoc.idTipoDoc
        End If
    End Sub

    Private Sub TIPODOCCONVIERTETextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TIPODOCCONVIERTETextBox.TextChanged
        If TIPODOCCONVIERTETextBox.Text.Trim.Length > 0 Then
            Me.lbTipoDocConvierte.Text = daTipoDoc.GetNombreTipoDoc(Me.TIPODOCCONVIERTETextBox.Text)
        Else
            Me.lbTipoDocConvierte.Text = ""
        End If
    End Sub

    Private Sub cbFiltroTipo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbFiltroTipo.SelectedIndexChanged
        Try
            If Not TypeOf cbFiltroTipo.ComboBox.SelectedValue Is DataRowView Then
                LlenaFiltroDocumento()
                GLO_TIPODOCUMENTOBindingSource.EndEdit()
                daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
                'If DsGlobal.GLO_TIPODOCUMENTO.GetChanges IsNot Nothing Then
                '    If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                '        daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
                '    Else
                '        GLO_TIPODOCUMENTOBindingSource.CancelEdit()
                '    End If
                'End If
                If cbFiltroTipo.ComboBox.SelectedValue IsNot Nothing AndAlso cbFiltroTipo.ComboBox.SelectedValue <> "-1" Then
                    daTipoDoc.FillByDocEs(DsGlobal.GLO_TIPODOCUMENTO, cbFiltroTipo.ComboBox.SelectedValue)
                    lbGlobalcom.cGeneral.ActivaControles(Me.Controls, True)
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub cbFiltroDocumento_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbFiltroDocumento.SelectedIndexChanged
        Try

            GLO_TIPODOCUMENTOBindingSource.EndEdit()
            daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
            'If DsGlobal.GLO_TIPODOCUMENTO.GetChanges IsNot Nothing Then
            '    If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            '        daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
            '    Else
            '        GLO_TIPODOCUMENTOBindingSource.CancelEdit()
            '    End If
            'End If
            If cbFiltroDocumento.ComboBox.SelectedValue IsNot Nothing Then
                daTipoDoc.FillByTipoDoc(DsGlobal.GLO_TIPODOCUMENTO, cbFiltroDocumento.ComboBox.SelectedValue)
                lbGlobalcom.cGeneral.ActivaControles(Me.Controls, True)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub GLO_TIPODOCUMENTOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_TIPODOCUMENTOBindingNavigatorSaveItem.Click
        Try

            GLO_TIPODOCUMENTOBindingSource.EndEdit()
            daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este tipo de docuemnto", "Elimina Tipo Documento", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                GLO_TIPODOCUMENTOBindingSource.Remove(GLO_TIPODOCUMENTOBindingSource.Current)
                daTipoDoc.Update(DsGlobal.GLO_TIPODOCUMENTO)
                daTipoDoc.FillByTipoDoc(DsGlobal.GLO_TIPODOCUMENTO, cbFiltroDocumento.ComboBox.SelectedValue)
                MessageBox.Show("Se elimino tipo documento con exito", "Elimina Tipo Documento", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
        Try
            lbGlobalcom.cGeneral.ActivaControles(Me.Controls, True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

   
    Private Sub btnBuscaDocGenera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaDocGenera.Click
        Dim fLDoc As New fListaTipoDocs
        If fLDoc.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.TIPODOCGENERATextBox.Text = fLDoc.idTipoDoc
        End If
    End Sub

    Private Sub TIPODOCGENERATextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TIPODOCGENERATextBox.TextChanged
        If TIPODOCGENERATextBox.Text.Trim.Length > 0 Then
            Me.lbTipoDocGenera.Text = daTipoDoc.GetNombreTipoDoc(Me.TIPODOCGENERATextBox.Text)
        Else
            Me.lbTipoDocGenera.Text = ""
        End If
    End Sub

    Private Sub btnCaja_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCaja.Click
        Try
            Dim flCaja As New fListaCajas
            flCaja.idSede = IDSEDETextBox.Text
            If flCaja.ShowDialog = Windows.Forms.DialogResult.OK Then
                Me.IDCAJATextBox.Text = flCaja.caja
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
End Class